package com.ljc.api;

import com.alibaba.fastjson.JSONObject;
import com.ljc.entity.RefreshTokenDetail;
import com.ljc.entity.User;
import com.ljc.entity.UserInfo;
import com.ljc.interfaces.UserApi;
import com.ljc.mapper.UserMapper;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

@DubboService
public class UserApiImpl implements UserApi {
    @Resource
    private UserMapper userMapper;

    /**
     * 通过手机号获取用户
     */
    @Override
    public User getUserByPhone(String phone) {
        return userMapper.getUserByPhone(phone);
    }

    /**
     * 添加用户
     */
    @Override
    public User addUser(User user) {
        userMapper.addUser(user);
        return user;
    }

    /**
     * 添加用户信息
     */
    @Override
    public Integer addUserInfo(UserInfo userInfo) {
        return userMapper.addUserInfo(userInfo);
    }

    /**
     * 根据id获取用户基本信息
     */
    @Override
    public User getUserById(Long userId) {
        return userMapper.getUserById(userId);
    }

    /**
     * 根据用户id获取用户详细信息
     */
    @Override
    public UserInfo getUserInfoByUserId(Long userId) {
        return userMapper.getUserInfoByUserId(userId);
    }

    /**
     * 更新用户信息
     */
    @Override
    public Integer updateUserInfos(UserInfo userInfo) {
        return userMapper.updateUserInfos(userInfo);
    }

    /**
     * 更新用户
     */
    @Override
    public void updateUsers(User user) {
        userMapper.updateUsers(user);
    }

    /**
     * 根据用户id集合获取其中的所有用户详细信息
     */
    @Override
    public List<UserInfo> getUserInfoByUserIdS(Set<Long> userIdList) {
        return userMapper.getUserInfoByUserIdS(userIdList);
    }

    /**
     * 查询用户数据分页的数量
     */
    @Override
    public Integer pageCountUserInfos(Map<String, Object> params) {
        return userMapper.pageCountUserInfos(params);
    }

    /**
     * 分页查询用户
     */
    @Override
    public List<UserInfo> pageListUserInfos(JSONObject params) {
        return userMapper.pageListUserInfos(params);
    }

    /**
     * 通过手机号或邮箱获取用户
     */
    @Override
    public User getUserByPhoneOrEmail(String phone, String email) {
        return userMapper.getUserByPhoneOrEmail(phone, email);
    }

    /**
     * 删除refresh-token
     */
    @Override
    public Integer deleteRefreshTokenByUserId(Long userId) {
        return userMapper.deleteRefreshTokenByUserId(userId);
    }

    /**
     * 添加refresh-token
     */
    @Override
    public Integer addRefreshToken(String refreshToken, Long userId, Date date) {
        return userMapper.addRefreshToken(refreshToken, userId, date);
    }

    /**
     * 用户退出则将refresh-token设置为无效
     */
    @Override
    public void deleteRefreshToken(String refreshToken, Long userId) {
        userMapper.deleteRefreshToken(refreshToken, userId);
    }

    /**
     * 刷新access-token
     */
    @Override
    public RefreshTokenDetail getRefreshTokenDetail(String refreshToken) {
        return userMapper.getRefreshTokenDetail(refreshToken);
    }

    /**
     * 根据用户id集合批量查询用户信息
     */
    @Override
    public List<UserInfo> batchGetUserInfoByUserIds(Set<Long> userIdList) {
        return userMapper.batchGetUserInfoByUserIds(userIdList);
    }
}
